Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices


Namespace Phoenix.Tools.Win32

  ''' <summary>
  ''' Structures to interoperate with the Windows 32 API  
  ''' </summary>

  '
   '* HANDLE - IntPtr
   '* BYTE - Byte
   '* SHORT - Int16
   '* WORD - UInt16
   '* INT - Int32
   '* UINT - UInt32
   '* LONG - INt32
   '* BOOL - Int32
   '* DWORD - UInt32
   '* ULONG - UInt32
   '* CHAR - Char
   '* LPSTR - String
   '* FLOAT - Single
   '* DOUBLE - Double
  '

#Region "CREATESTRUCT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure CREATESTRUCT
        Private lpCreateParams As IntPtr
        Private hInstance As IntPtr
        Private hMenu As IntPtr
        Private hwndParent As IntPtr
        Private cy As Integer
        Private cx As Integer
        Private y As Integer
        Private x As Integer
        Private style As Int32
        Private lpszName As String
        Private lpszClass As String
        Private dwExStyle As UInt32
    End Structure
#End Region

#Region "SpinControls"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure UDACCEL
        Public nSec As UInt32
        Public nInc As UInt32
    End Structure
#End Region

#Region "SIZE"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SIZE
        Public cx As Integer
        Public cy As Integer
    End Structure
#End Region

#Region "RECT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure RECT
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer

        '       'TODO: INSTANT VB TODO TASK: The following operator was converted, but you will need VB.NET 2005 to compile it:
        'Public Shared Widening Operator CType(ByVal rect As RECT) As Rectangle
        '  Return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom)
        'End Operator

        '       'TODO: INSTANT VB TODO TASK: The following operator was converted, but you will need VB.NET 2005 to compile it:
        'Public Shared Widening Operator CType(ByVal rect As RECT) As Size
        '  Return New Size(rect.right - rect.left, rect.bottom - rect.top)
        'End Operator

        '       'TODO: INSTANT VB TODO TASK: The following operator was converted, but you will need VB.NET 2005 to compile it:
        'Public Shared Narrowing Sub CType(ByVal rect As Rectangle)
        '       Dim rc As RECT = New RECT

        '  rc.left = rect.Left
        '  rc.right = rect.Right
        '  rc.top = rect.Top
        '  rc.bottom = rect.Bottom

        '  Return rc
        'End Sub
    End Structure

#End Region

#Region "INITCOMMONCONTROLSEX"
    <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    Public Class INITCOMMONCONTROLSEX
        Public dwSize As Integer
        Public dwICC As Integer
    End Class
#End Region

#Region "TBBUTTON"
    <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    Public Structure TBBUTTON
        Public iBitmap As Integer
        Public idCommand As Integer
        Public fsState As Byte
        Public fsStyle As Byte
        Public bReserved0 As Byte
        Public bReserved1 As Byte
        Public dwData As Integer
        Public iString As Integer
    End Structure
#End Region

#Region "POINT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure POINT
        Public x As Integer
        Public y As Integer


        'INSTANT VB NOTE: The parameter X was renamed since Visual Basic will not uniquely identify class members when parameters have the same name:
        'INSTANT VB NOTE: The parameter Y was renamed since Visual Basic will not uniquely identify class members when parameters have the same name:
        Public Sub New(ByVal X_Renamed As Integer, ByVal Y_Renamed As Integer)
            x = X_Renamed
            y = Y_Renamed
        End Sub
        ''' <summary>
        ''' Point creation from lParam `s data
        ''' </summary>
        ''' <param name="lParam"></param>
        Public Sub New(ByVal lParam As Integer)
            x = (lParam And &HFFFF)
            y = (lParam >> 16)
        End Sub

        '       'TODO: INSTANT VB TODO TASK: The following operator was converted, but you will need VB.NET 2005 to compile it:
        'Public Shared Widening Operator CType(ByVal p As POINT) As System.Drawing.Point
        '  Return New System.Drawing.Point(p.x, p.y)
        'End Operator

        '       'TODO: INSTANT VB TODO TASK: The following operator was converted, but you will need VB.NET 2005 to compile it:
        'Public Shared Widening Sub CType(ByVal p As System.Drawing.Point)
        '  Return New POINT(p.X, p.Y)
        'End Sub

    End Structure
#End Region

#Region "NMHDR"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMHDR
        Public hwndFrom As IntPtr
        Public idFrom As Integer
        Public code As Integer
    End Structure
#End Region

#Region "NMCUSTOMDRAW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMCUSTOMDRAW
        Public hdr As NMHDR
        Public dwDrawStage As Integer
        Public hdc As IntPtr
        Public rc As RECT
        Public dwItemSpec As Integer
        Public uItemState As Integer
        Public lItemlParam As Integer
    End Structure
#End Region

#Region "NMTBCUSTOMDRAW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMTBCUSTOMDRAW
        Public nmcd As NMCUSTOMDRAW
        Public hbrMonoDither As IntPtr
        Public hbrLines As IntPtr
        Public hpenLines As IntPtr
        Public clrText As Integer
        Public clrMark As Integer
        Public clrTextHighlight As Integer
        Public clrBtnFace As Integer
        Public clrBtnHighlight As Integer
        Public clrHighlightHotTrack As Integer
        Public rcText As RECT
        Public nStringBkMode As Integer
        Public nHLStringBkMode As Integer
    End Structure
#End Region

#Region "NMLVCUSTOMDRAW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMLVCUSTOMDRAW
        Public nmcd As NMCUSTOMDRAW
        Public clrText As System.UInt32
        Public clrTextBk As System.UInt32
        Public iSubItem As Integer
    End Structure
#End Region

#Region "TOOLTIP CONTROL STRUCTS"
#Region "TOOLTIPTEXTA || NMTTDISPINFO"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
    Public Structure TOOLTIPTEXTA
        Public hdr As NMHDR
        Public lpszText As IntPtr
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szText As String
        Public hinst As IntPtr
        Public uFlags As Integer
    End Structure
#End Region

#Region "TOOLTIPTEXT || NMTTDISPINFO"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure TOOLTIPTEXT
        Public hdr As NMHDR
        Public lpszText As IntPtr
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szText As String
        Public hinst As IntPtr
        Public uFlags As Integer
    End Structure
#End Region

#Region "NMTTCUSTOMDRAW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMTTCUSTOMDRAW
        Public nmcd As NMCUSTOMDRAW
        Public uDrawFlags As UInt32
    End Structure
#End Region

#Region "NMTTDISPINFO"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure NMTTDISPINFO
        Public hdr As NMHDR
        Public lpszText As IntPtr
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szText As String
        Public hinst As IntPtr
        Public uFlags As Integer
    End Structure
#End Region

#Region "TOOLINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure TOOLINFO
        Public cbSize As UInt32
        Public uFlags As UInt32
        Public hwnd As IntPtr
        Public uId As IntPtr ' UINT_PTR
        Public rect As RECT
        Public hinst As IntPtr
        <MarshalAs(UnmanagedType.LPTStr)> _
        Public lpszText As String
        'public IntPtr	  lpszText; 
        Public lParam As IntPtr
    End Structure
#End Region

#Region "TTHITTESTINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure TTHITTESTINFO
        Public hwnd As IntPtr
        Public pt As POINT
        Public ti As TOOLINFO
    End Structure
#End Region

#Region "TTGETTITLE"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure TTGETTITLE
        Public dwSize As UInt32
        Public uTitleBitmap As UInt32
        Public cch As UInt32
        Public pszTitle As IntPtr
    End Structure
#End Region
#End Region

#Region "TBBUTTONINFO"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure TBBUTTONINFO
        Public cbSize As Integer
        Public dwMask As Integer
        Public idCommand As Integer
        Public iImage As Integer
        Public fsState As Byte
        Public fsStyle As Byte
        Public cx As Short
        Public lParam As IntPtr
        Public pszText As IntPtr
        Public cchText As Integer
    End Structure
#End Region

#Region "REBARBANDINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure REBARBANDINFO
        Public cbSize As Integer
        Public fMask As Integer
        Public fStyle As Integer
        Public clrFore As Integer
        Public clrBack As Integer
        Public lpText As IntPtr
        Public cch As Integer
        Public iImage As Integer
        Public hwndChild As IntPtr
        Public cxMinChild As Integer
        Public cyMinChild As Integer
        Public cx As Integer
        Public hbmBack As IntPtr
        Public wID As Integer
        Public cyChild As Integer
        Public cyMaxChild As Integer
        Public cyIntegral As Integer
        Public cxIdeal As Integer
        Public lParam As Integer
        Public cxHeader As Integer
    End Structure
#End Region

#Region "MOUSEHOOKSTRUCT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MOUSEHOOKSTRUCT
        Public pt As POINT
        Public hwnd As IntPtr
        Public wHitTestCode As Integer
        Public dwExtraInfo As IntPtr
    End Structure
#End Region

#Region "NMTOOLBAR"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMTOOLBAR
        Public hdr As NMHDR
        Public iItem As Integer
        Public tbButton As TBBUTTON
        Public cchText As Integer
        Public pszText As IntPtr
        Public rcButton As RECT
    End Structure
#End Region

#Region "NMREBARCHEVRON"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMREBARCHEVRON
        Public hdr As NMHDR
        Public uBand As Integer
        Public wID As Integer
        Public lParam As Integer
        Public rc As RECT
        Public lParamNM As Integer
    End Structure
#End Region

#Region "NMREBARCHILDSIZE"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMREBARCHILDSIZE
        Public hdr As NMHDR
        Public uBand As UInt32
        Public wID As UInt32
        Public rcChild As RECT
        Public rcBand As RECT
    End Structure
#End Region

#Region "BITMAP"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure BITMAP
        Public bmType As Long
        Public bmWidth As Long
        Public bmHeight As Long
        Public bmWidthBytes As Long
        Public bmPlanes As Short
        Public bmBitsPixel As Short
        Public bmBits As IntPtr
    End Structure
#End Region

#Region "BITMAPINFO_FLAT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure BITMAPINFO_FLAT
        Public bmiHeader_biSize As Integer
        Public bmiHeader_biWidth As Integer
        Public bmiHeader_biHeight As Integer
        Public bmiHeader_biPlanes As Short
        Public bmiHeader_biBitCount As Short
        Public bmiHeader_biCompression As Integer
        Public bmiHeader_biSizeImage As Integer
        Public bmiHeader_biXPelsPerMeter As Integer
        Public bmiHeader_biYPelsPerMeter As Integer
        Public bmiHeader_biClrUsed As Integer
        Public bmiHeader_biClrImportant As Integer
        <MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1024)> _
        Public bmiColors As Byte()
    End Structure
#End Region

#Region "RGBQUAD"
    Public Structure RGBQUAD
        Public rgbBlue As Byte
        Public rgbGreen As Byte
        Public rgbRed As Byte
        Public rgbReserved As Byte
    End Structure
#End Region

#Region "BITMAPINFOHEADER"
    <StructLayout(LayoutKind.Sequential)> _
    Public Class BITMAPINFOHEADER
        Public biSize As Integer = Marshal.SizeOf(GetType(BITMAPINFOHEADER))
        Public biWidth As Integer
        Public biHeight As Integer
        Public biPlanes As Short
        Public biBitCount As Short
        Public biCompression As Integer
        Public biSizeImage As Integer
        Public biXPelsPerMeter As Integer
        Public biYPelsPerMeter As Integer
        Public biClrUsed As Integer
        Public biClrImportant As Integer
    End Class
#End Region

#Region "BITMAPINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Class BITMAPINFO
        Public bmiHeader As BITMAPINFOHEADER = New BITMAPINFOHEADER
        <MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1024)> _
        Public bmiColors As Byte()
    End Class
#End Region

#Region "PALETTEENTRY"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure PALETTEENTRY
        Public peRed As Byte
        Public peGreen As Byte
        Public peBlue As Byte
        Public peFlags As Byte
    End Structure
#End Region

#Region "MSG"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MSG
        Public hwnd As IntPtr
        Public message As Integer
        Public wParam As IntPtr
        Public lParam As IntPtr
        Public time As Integer
        Public pt_x As Integer
        Public pt_y As Integer
    End Structure
#End Region

#Region "HD_HITTESTINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure HD_HITTESTINFO
        Public pt As POINT
        Public flags As System.UInt32
        Public iItem As Integer
    End Structure
#End Region

#Region "DLLVERSIONINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure DLLVERSIONINFO
        Public cbSize As Integer
        Public dwMajorVersion As Integer
        Public dwMinorVersion As Integer
        Public dwBuildNumber As Integer
        Public dwPlatformID As Integer
    End Structure
#End Region

#Region "PAINTSTRUCT"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure PAINTSTRUCT
        Public hdc As IntPtr
        Public fErase As Integer
        Public rcPaint As Rectangle
        Public fRestore As Integer
        Public fIncUpdate As Integer
        Public Reserved1 As Integer
        Public Reserved2 As Integer
        Public Reserved3 As Integer
        Public Reserved4 As Integer
        Public Reserved5 As Integer
        Public Reserved6 As Integer
        Public Reserved7 As Integer
        Public Reserved8 As Integer
    End Structure
#End Region

#Region "BLENDFUNCTION"
    <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    Public Structure BLENDFUNCTION
        Public BlendOp As Byte
        Public BlendFlags As Byte
        Public SourceConstantAlpha As Byte
        Public AlphaFormat As Byte
    End Structure

#End Region

#Region "TRACKMOUSEEVENTS"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure TRACKMOUSEEVENTS
        Public cbSize As System.UInt32
        Public dwFlags As System.UInt32
        Public hWnd As IntPtr
        Public dwHoverTime As System.UInt32
    End Structure
#End Region

#Region "STRINGBUFFER"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure STRINGBUFFER
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=512)> _
        Public szText As String
    End Structure
#End Region

#Region "NMTVCUSTOMDRAW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMTVCUSTOMDRAW
        Public nmcd As NMCUSTOMDRAW
        Public clrText As System.UInt32
        Public clrTextBk As System.UInt32
        Public iLevel As Integer
    End Structure
#End Region

#Region "NMTREEVIEW"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure NMTREEVIEW
        Public hdr As NMHDR
        Public action As System.UInt32
        Public itemOld As TVITEM
        Public itemNew As TVITEM
        Public ptDrag As POINT
    End Structure

#End Region

#Region "TVITEM"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure TVITEM
        Public mask As System.UInt32
        Public hItem As IntPtr
        Public state As System.UInt32
        Public stateMask As System.UInt32
        Public pszText As IntPtr
        Public cchTextMax As Integer
        Public iImage As Integer
        Public iSelectedImage As Integer
        Public cChildren As Integer
        Public lParam As Integer
    End Structure
#End Region

#Region "TVHITTESTINFO"
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure TVHITTESTINFO
        Public pt As POINT
        Public flags_Renamed As UInt32
        Public hItem As IntPtr

        Public Property Flags() As TVHitTestFlags
            Get
                Return CType(Convert.ToInt32(flags_Renamed), TVHitTestFlags)
            End Get
            Set(ByVal Value As TVHitTestFlags)
                flags_Renamed = Convert.ToUInt32(Value)
            End Set
        End Property

    End Structure

#End Region

#Region "TVINSERTSTRUCT"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure TVINSERTSTRUCT
        Private hParent As Integer
        Private hInsertAfter As Integer
        Private item As TVITEM
    End Structure
#End Region

#Region "LVITEM"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure LVITEM
        Public mask As System.UInt32
        Public iItem As Integer
        Public iSubItem As Integer
        Public state As System.UInt32
        Public stateMask As System.UInt32
        Public pszText As IntPtr
        Public cchTextMax As Integer
        Public iImage As Integer
        Public lParam As Integer
        Public iIndent As Integer
    End Structure
#End Region

#Region "HDITEM"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure HDITEM
        Public mask As System.UInt32
        Public cxy As Integer
        Public pszText As IntPtr
        Public hbm As IntPtr
        Public cchTextMax As Integer
        Public fmt As Integer
        Public lParam As Integer
        Public iImage As Integer
        Public iOrder As Integer
    End Structure
#End Region

#Region "WINDOWPLACEMENT"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure WINDOWPLACEMENT
        Public length As System.UInt32
        Public flags As System.UInt32
        Public showCmd As System.UInt32
        Public ptMinPosition As POINT
        Public ptMaxPosition As POINT
        Public rcNormalPosition As RECT
    End Structure
#End Region

#Region "SCROLLINFO"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure SCROLLINFO
        Public cbSize As System.UInt32
        Public fMask As System.UInt32
        Public nMin As Integer
        Public nMax As Integer
        Public nPage As System.UInt32
        Public nPos As Integer
        Public nTrackPos As Integer
    End Structure
#End Region

#Region "NOTIFYICONDATA"
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
    Public Structure NOTIFYICONDATA
        Public cbSize As UInt32 ' DWORD
        Public hWnd As IntPtr ' HWND
        Public uID As UInt32 ' UINT
        Public uFlags As NotifyFlags ' UINT
        Public uCallbackMessage As UInt32 ' UINT
        Public hIcon As IntPtr ' HICON
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
        Public szTip As String ' char[128]
        Public dwState As NotifyState ' DWORD
        Public dwStateMask As NotifyState ' DWORD
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
        Public szInfo As String ' char[256]
        Public uTimeoutOrVersion As UInt32 ' UINT
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _
        Public szInfoTitle As String ' char[64]
        Public dwInfoFlags As NotifyInfoFlags ' DWORD
    End Structure
#End Region

#Region "PARAFORMAT2"
    '
    'typedef struct _paraformat {
    'UINT cbSize;
    'DWORD dwMask;
    'WORD wNumbering;
    'WORD wEffects;
    'LONG dxStartIndent;
    'LONG dxRightIndent;
    'LONG dxOffset;
    'WORD wAlignment;
    'SHORT cTabCount;
    'LONG rgxTabs[MAX_TAB_STOPS];
    'LONG dySpaceBefore;
    'LONG dySpaceAfter;
    'LONG dyLineSpacing;
    'SHORT sStyle;
    'BYTE bLineSpacingRule;
    'BYTE bOutlineLevel;
    'WORD wShadingWeight;
    'WORD wShadingStyle;
    'WORD wNumberingStart;
    'WORD wNumberingStyle;
    'WORD wNumberingTab;
    'WORD wBorderSpace;
    'WORD wBorderWidth;
    'WORD wBorders;
    '} PARAFORMAT2;
    '


    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Public Structure PARAFORMAT2
        Public cbSize As UInt32
        Public dwMask As UInt32
        Public wNumbering As UInt16
        Public wEffects As UInt16
        Public dxStartIndent As Int32
        Public dxRightIndent As Int32
        Public dxOffset As Int32
        Public wAlignment As UInt16
        Public cTabCount As Int16
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
        Public rgxTabs As Int32()
        Public dySpaceBefore As Int32
        Public dySpaceAfter As Int32
        Public dyLineSpacing As Int32
        Public sStyle As Int16
        Public bLineSpacingRule As Byte
        Public bOutlineLevel As Byte
        Public wShadingWeight As UInt16
        Public wShadingStyle As UInt16
        Public wNumberingStart As UInt16
        Public wNumberingStyle As UInt16
        Public wNumberingTab As UInt16
        Public wBorderSpace As UInt16
        Public wBorderWidth As UInt16
        Public wBorders As UInt16
    End Structure
#End Region


    <StructLayout(LayoutKind.Sequential)> _
   Public Structure CHARRANGE
        Public cpMin As Integer
        Public cpMax As Integer
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
     Public Structure FORMATRANGE
        Public hdc As IntPtr
        Public hdcTarget As IntPtr
        Public rc As RECT
        Public rcPage As RECT
        Public chrg As CHARRANGE
    End Structure

#Region "Shell"
    <ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000002-0000-0000-C000-000000000046")> _
    Public Interface IMalloc
        ' Allocates a block of memory.
        ' Return value: a pointer to the allocated memory block.
        <PreserveSig()> _
        Function Alloc(ByVal cb As UInt32) As IntPtr ' Size, in bytes, of the memory block to be allocated.

        ' Changes the size of a previously allocated memory block.
        ' Return value:  Reallocated memory block 
        <PreserveSig()> _
        Function Realloc(ByVal pv As IntPtr, ByVal cb As UInt32) As IntPtr ' Size of the memory block (in bytes) to be reallocated.

        ' Frees a previously allocated block of memory.
        <PreserveSig()> _
        Sub Free(ByVal pv As IntPtr) ' Pointer to the memory block to be freed.

        ' This method returns the size (in bytes) of a memory block previously
        ' allocated with IMalloc::Alloc or IMalloc::Realloc.
        ' Return value: The size of the allocated memory block in bytes 
        <PreserveSig()> _
        Function GetSize(ByVal pv As IntPtr) As UInt32 ' Pointer to the memory block for which the size
        ' is requested.

        ' This method determines whether this allocator was used to allocate
        ' the specified block of memory.
        ' Return value: 1 - allocated 0 - not allocated by this IMalloc instance. 
        <PreserveSig()> _
        Function DidAlloc(ByVal pv As IntPtr) As Int16 ' Pointer to the memory block

        ' This method minimizes the heap as much as possible by releasing unused
        ' memory to the operating system, 
        ' coalescing adjacent free blocks and committing free pages.
        <PreserveSig()> _
        Sub HeapMinimize()
    End Interface


    <ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214E6-0000-0000-C000-000000000046")> _
    Public Interface IShellFolder
        ' Translates a file object's or folder's display name into an item identifier list.
        ' Return value: error code, if any
        ' parsing operation. This parameter is  ' Optional bind context that controls the
        ' normally set to NULL. 
        ' display name. ' Null-terminated UNICODE string with the
        ' number of characters of the  ' Pointer to a ULONG value that receives the
        ' display name that was parsed.
        ' the item identifier list for  ' Pointer to an ITEMIDLIST pointer that receives
        ' the object.
        <PreserveSig()> _
        Function ParseDisplayName(ByVal hwnd As IntPtr, ByVal pbc As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszDisplayName As String, ByRef pchEaten As UInt32, <System.Runtime.InteropServices.Out()> ByRef ppidl As IntPtr, ByRef pdwAttributes As UInt32) As Int32 ' Optional parameter that can be used to
        ' query for file attributes.
        ' this can be values from the SFGAO enum

        ' Allows a client to determine the contents of a folder by creating an item
        ' identifier enumeration object and returning its IEnumIDList interface.
        ' Return value: error code, if any
        ' enumeration, this window handle  ' If user input is required to perform the
        ' should be used by the enumeration object as
        ' the parent window to take 
        ' user input.
        ' enumeration. For a list  ' Flags indicating which items to include in the
        ' of possible values, see the SHCONTF enum. 
        <PreserveSig()> _
        Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As Int32, <System.Runtime.InteropServices.Out()> ByRef ppenumIDList As IntPtr) As Int32 ' Address that receives a pointer to the
        ' IEnumIDList interface of the 
        ' enumeration object created by this method. 

        ' Retrieves an IShellFolder object for a subfolder.
        ' Return value: error code, if any
        ' that identifies the subfolder. ' Address of an ITEMIDLIST structure (PIDL)
        ' a bind context object to be  ' Optional address of an IBindCtx interface on
        ' used during this operation.
        <PreserveSig()> _
        Function BindToObject(ByVal pidl As IntPtr, ByVal pbc As IntPtr, ByVal riid As Guid, <System.Runtime.InteropServices.Out()> ByRef ppv As IntPtr) As Int32 ' Address that receives the interface pointer.

        ' Requests a pointer to an object's storage interface. 
        ' Return value: error code, if any
        ' identifies the subfolder relative  ' Address of an ITEMIDLIST structure that
        ' to its parent folder. 
        ' bind context object to be  ' Optional address of an IBindCtx interface on a
        ' used during this operation.
        ' storage interface. ' Interface identifier (IID) of the requested
        <PreserveSig()> _
        Function BindToStorage(ByVal pidl As IntPtr, ByVal pbc As IntPtr, ByVal riid As Guid, <System.Runtime.InteropServices.Out()> ByRef ppv As IntPtr) As Int32 ' Address that receives the interface pointer specified by riid.

        ' Determines the relative order of two file objects or folders, given their
        ' item identifier lists. Return value: If this method is successful, the
        ' CODE field of the HRESULT contains one of the following values (the code
        ' can be retrived using the helper function GetHResultCode): Negative A
        ' negative return value indicates that the first item should precede
        ' the second (pidl1 < pidl2). 

        ' Positive A positive return value indicates that the first item should
        ' follow the second (pidl1 > pidl2).  Zero A return value of zero
        ' indicates that the two items are the same (pidl1 = pidl2). 
        ' should be performed. The lower  ' Value that specifies how the comparison
        ' Sixteen bits of lParam define the sorting rule.
        ' The upper sixteen bits of 
        ' lParam are used for flags that modify the
        ' sorting rule. values can be from 
        ' the SHCIDS enum
        <PreserveSig()> _
        Function CompareIDs(ByVal lParam As Int32, ByVal pidl1 As IntPtr, ByVal pidl2 As IntPtr) As Int32 ' Pointer to the second item's ITEMIDLIST structure.

        ' Requests an object that can be used to obtain information from or interact
        ' with a folder object.
        ' Return value: error code, if any
        <PreserveSig()> _
        Function CreateViewObject(ByVal hwndOwner As IntPtr, ByVal riid As Guid, <System.Runtime.InteropServices.Out()> ByRef ppv As IntPtr) As Int32 ' Address of a pointer to the requested interface.

        ' Retrieves the attributes of one or more file objects or subfolders. 
        ' Return value: error code, if any
        ' attributes.  ' Number of file objects from which to retrieve
        ' structures, each of which  ' Address of an array of pointers to ITEMIDLIST
        ' uniquely identifies a file object relative to
        ' the parent folder.
        <PreserveSig()> _
        Function GetAttributesOf(ByVal cidl As UInt32, <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=0)> ByVal apidl As IntPtr(), ByRef rgfInOut As UInt32) As Int32 ' Address of a single ULONG value that, on entry,
        ' contains the attributes that 
        ' the caller is requesting. On exit, this value
        ' contains the requested 
        ' attributes that are common to all of the
        ' specified objects. this value can
        ' be from the SFGAO enum

        ' Retrieves an OLE interface that can be used to carry out actions on the
        ' specified file objects or folders.
        ' Return value: error code, if any
        ' should specify if it displays  ' Handle to the owner window that the client
        ' a dialog box or message box.
        ' in the apidl parameter.  ' Number of file objects or subfolders specified
        ' structures, each of which  ' Address of an array of pointers to ITEMIDLIST
        ' uniquely identifies a file object or subfolder
        ' relative to the parent folder.
        <PreserveSig()> _
        Function GetUIObjectOf(ByVal hwndOwner As IntPtr, ByVal cidl As UInt32, ByVal apidl As IntPtr(), ByVal riid As Guid, ByRef rgfReserved As UInt32, <System.Runtime.InteropServices.Out()> ByRef ppv As IntPtr) As Int32 ' Pointer to the requested interface.

        ' Retrieves the display name for the specified file object or subfolder. 
        ' Return value: error code, if any
        ' that uniquely identifies the file  ' Address of an ITEMIDLIST structure (PIDL)
        ' object or subfolder relative to the parent folder. 
        ' to return. For a list of  ' Flags used to request the type of display name
        ' possible values, see the SHGNO enum. 
        <PreserveSig()> _
        Function GetDisplayNameOf(ByVal pidl As IntPtr, ByVal uFlags As UInt32, <System.Runtime.InteropServices.Out()> ByRef pName As STRRET) As Int32 ' Address of a STRRET structure in which to
        ' return the display name.

        ' Sets the display name of a file object or subfolder, changing the item
        ' identifier in the process.
        ' Return value: error code, if any
        ' message boxes that the client  ' Handle to the owner window of any dialog or
        ' displays.
        ' identifies the file object ' Pointer to an ITEMIDLIST structure that uniquely
        ' or subfolder relative to the parent folder. 
        ' specifies the new display name.  ' Pointer to a null-terminated string that
        ' the lpszName parameter. For a list of possible ' Flags indicating the type of name specified by
        ' values, see the description of the SHGNO enum. 
        <PreserveSig()> _
        Function SetNameOf(ByVal hwnd As IntPtr, ByVal pidl As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszName As String, ByVal uFlags As UInt32, <System.Runtime.InteropServices.Out()> ByRef ppidlOut As IntPtr) As Int32 ' Address of a pointer to an ITEMIDLIST structure
        ' which receives the new ITEMIDLIST. 
    End Interface


    ''' <summary>
    ''' Contains parameters for the SHBrowseForFolder function and
    ''' receives information about the folder selected 
    ''' by the user.
    ''' </summary>

    '[StructLayout(LayoutKind.Sequential)]
    Public Structure BROWSEINFO
        Public hwndOwner As IntPtr ' Handle to the owner window for the
        ' dialog box.
        Public pidlRoot As IntPtr ' Pointer to an item identifier list
        ' (PIDL) specifying the location of
        ' the root folder from which to start
        ' browsing.
        ' display name of the  ' Address of a buffer to receive the
        <MarshalAs(UnmanagedType.LPStr)> _
        Public pszDisplayName As String ' folder selected by the user.
        ' that is displayed  ' Address of a null-terminated string
        <MarshalAs(UnmanagedType.LPStr)> _
        Public lpszTitle As String ' above the tree view control in the
        ' dialog box.
        Public ulFlags As UInt32 ' Flags specifying the options for the
        ' dialog box.
        ' function that the  ' Address of an application-defined
        <MarshalAs(UnmanagedType.FunctionPtr)> _
        Public lpfn As WindowsAPI.BrowseCallbackProc ' dialog box calls when an event occurs.
        Public lParam As Int32 ' Application-defined value that the
        ' dialog box passes to 
        ' the callback function
        Public iImage As Int32 ' Variable to receive the image
        ' associated with the selected folder.
    End Structure


    <StructLayout(LayoutKind.Explicit)> _
    Public Structure STRRET
        <FieldOffset(0)> _
        Public uType As UInt32 ' One of the STRRET_* values

        <FieldOffset(4)> _
        Public pOleStr As IntPtr ' must be freed by caller of GetDisplayNameOf

        <FieldOffset(4)> _
        Public pStr As IntPtr ' NOT USED

        <FieldOffset(4)> _
        Public uOffset As UInt32 ' Offset into SHITEMID

        'TODO: INSTANT VB TODO TASK: cStr is a keyword in VB.NET. Change the name or use square brackets to override it:
        <FieldOffset(4)> _
        Public cStr_Renamed As IntPtr ' Buffer to fill in (ANSI)
    End Structure



#End Region
End Namespace

